<?php

class ErrorController extends Zend_Controller_Action
{

    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');
        
        $this->view->headTitle('An error occurred');
        
        $previous_request=$errors->request;



        if($previous_request->isXmlHttpRequest())
        {
            $this->_helper->layout->disableLayout();
            $this->getResponse()->setHttpResponseCode(200);
        }
        
        $this->view->message =$errors->type;;

        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                // 404 error -- controller or action not found
                if(!$previous_request->isXmlHttpRequest())                
                    $this->getResponse()->setHttpResponseCode(404);
                break;
            default:
                // application error
                if(!$previous_request->isXmlHttpRequest())
                    $this->getResponse()->setHttpResponseCode(500);
                break;
        }

        // conditionally display exceptions
        if ($this->getInvokeArg('displayExceptions') == true) {
            $this->view->exception = $errors->exception;
        }



        $this->view->request   = $errors->request;
        
        
    }


    public function deniedAction(){
        
        $this->view->headTitle('Access denied');
    }
	
    
    

}
